#pragma once
#ifndef ANNWARPER_EIGEN_H_
#define ANNWARPER_EIGEN_H_

#include <Common/GlobalDefines.h>
#include "ANN.h"
#include "Eigen/Dense"
#include <vector>

#pragma comment(lib, "ann.lib")

GLOBAL_NAMESPACE_BEGIN

class AnnWarper_Eigen
{
public:
	AnnWarper_Eigen() {
		ann_kdTree_ = NULL;
		dataPts_ = NULL;
		k_knn_ = 10;
		dim_ = 3;
		max_query_time_ = 3;
	}
	~AnnWarper_Eigen() {
		destroy();
	}

public:
	void init(const Eigen::MatrixXd& points);
	void init(const Eigen::MatrixXd& points, const std::vector<bool>& bTags);
	void destroy();

	void setFlags(const std::vector<bool>& flags);
	int queryPoint(const Eigen::VectorXd& pQuery, int nearNum, std::vector<int>& nnIdx, std::vector<double>& nnDists);
    int queryPointIds(const Eigen::VectorXd& pQuery, int nearNum, std::vector<int>& nnIdx);
    int queryFRPoint(const Eigen::VectorXd& pQuery, float sqRad, int k, std::vector<int>& nnIdx, std::vector<double>& nnDists);

private:
	ANNkd_tree *ann_kdTree_;
	int nPts_;
	int dim_;
	int k_knn_;
	ANNpointArray	dataPts_;
	ANNpoint		queryPt_;
	std::vector<bool> ptTags_;

	int max_query_time_;
	//Eigen::VectorXi mapIdx_;
};

GLOBAL_NAMESPACE_END

#endif//ANNWARPER_EIGEN_H_